﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace TrabiBT
{
    public partial class MainWindow : Form
    {

        private int chartCount = 0;
        public MainWindow()
        {
            InitializeComponent();
            /* Initialize application */
            App.Initialize(this);
        }

        public Panel PanelChart
        {
            get { return this.panelChart; }
        }

        public int ChartCount
        {
            get { return this.chartCount; }
            set { this.chartCount = value; }
        }

        public Label StatusLabel
        {
            get { return this.statusLabel; }
        }

        private void connectToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            App.Instance.StartSession();
        }

        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            App.Instance.ModifySettings();
        }



        protected override void OnPaint(PaintEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            Invalidate();
            if (App.Instance.CurrentSession != null)
            {
                if (App.Instance.CurrentSession.Data != 0)
                {
                    label2.Text = App.Instance.CurrentSession.Data.ToString();
                }
                App.Instance.CurrentSession.UpdateData();
            }
        }


        private void addButton_Click(object sender, EventArgs e)
        {
            Variable var = new Variable(Convert.ToInt32(this.addressBox.Text.ToString(),16), 0x3004,this.typeCBox.Text.ToString());
            ViewVariableText textview = new ViewVariableText(nameBox.Text.ToString(),addressBox.Text.ToString(),var);

            var.AddView(textview);
            if (App.Instance.CurrentSession != null)
            {
                App.Instance.CurrentSession.AddVar(Convert.ToInt32(this.addressBox.Text.ToString(),16),var);
            }
           this.DataPanel1.Controls.Add(textview);
        }

        private void quitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            App.Instance.MainForm.Close();
        }

        private void reconnectBtn_Click(object sender, EventArgs e)
        {
            App.Instance.CurrentSession.ConnectToDevice();
            statusLabel.Text = "Connected";
        }





    }
}
